# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"
  lane :custom_lane do
    # add actions here: https://docs.fastlane.tools/actions
  end

# 所有lane执行之前
  before_all do |lane, options|
  #   cocoapods
  end
  
  lane :Debug do
    #buildScheme = ENV['SCHEME_NAME']#options[:buildScheme]
    outputName = "#{Time.now.strftime("%Y-%m-%d-%H-%M")}_一点学习_Debug"
    increment_build_number_in_plist
    build_app(
      scheme: "YiDian",
      export_method: "development",
      configuration: "Debug",
      output_directory: "build",
      output_name: outputName,
      include_bitcode: true
    )
    scp(
      host: "192.168.2.150",
      username: "ios",
      upload: {
        src: "build/#{outputName}.ipa",
        dst: "/opt/app/php/softwarePackage/ios/"
      }
    )
  end

  lane :Release do
  outputName = "#{Time.now.strftime("%Y-%m-%d-%H-%M")}_一点学习_Release"
  increment_build_number_in_plist
  build_app(
    scheme: "YiDian",
    export_method: "development",
    configuration: "Release",
    output_directory: "build",
    output_name: outputName,
    include_bitcode: true
  )
  end

  # 打 app store 的lane
  lane :store do
    cert(output_path: "build",)

    sigh(output_path: "build", readonly: true, adhoc: false,)
    outputName = "#{Time.now.strftime("%Y-%m-%d-%H-%M")}_一点学习_App Store"
    increment_build_number_in_plist
    build_app(
      scheme: "YiDian",
      export_method: "app-store", 
      buildlog_path: "./fastlane/fastlanelog",
      output_directory: "build",
      output_name: outputName,
      include_bitcode: true,
    )
  end

  # 打 adhoc 的 lane
  lane :adhoc do
    cert(output_path: "build",)

    sigh(output_path: "build", readonly: true, adhoc: true,)

    outputName = "#{Time.now.strftime("%Y-%m-%d-%H-%M")}_一点学习_Debug"
    increment_build_number_in_plist
    build_app(
      scheme: "YiDian",
      export_method: "ad-hoc", 
      buildlog_path: "./fastlane/fastlanelog",
      output_directory: "build",
      output_name: outputName,
      include_bitcode: true,
    )
  end

  # 打 development 的 lane
  lane :development do
    # cert(output_path: "build",)

    # sigh(output_path: "build", readonly: false, adhoc: true,)
    outputName = "#{Time.now.strftime("%Y-%m-%d-%H-%M")}_一点学习_Debug"
    increment_build_number_in_plist
    build_app(
      scheme: "YiDian",
      export_method: "development", 
      buildlog_path: "./fastlane/fastlanelog",
      output_directory: "build",
      output_name: outputName,
      include_bitcode: true,
    )

    upload_to_testflight(changelog: "* fix bug")
  end


  # 所有lane完成之后，可以适用参数lane来区分
  after_all do |lane|


  end

  # # 打一个企业版包
  # lane :ent do |options|
  #   # action(cert)，下载[开发者证书.cer]
  #   # 下载的文件会存在项目根目录的build文件夹下
  #   # 若工程目录没有 [含有开发者账号的keychain备份] 或者 [使用后登录失败]，
  #   # fastlane会让你在命令行登录开发者账号，登录成功后，会在你的[钥匙串]中创建一个 {deliver.[username]} 的登录账户
  #   cert(
  #     # Appfile设置了这边就可以不用了
  #     # username: "com.devhy.testEnt",
  #     # team_id: "TEAMIDXXX1",

  #     # 下载文件的位置
  #     output_path: "build",
  #   )

  #   # action(sigh)，下载[安装app匹配的Provision Profile文件(PP文件)]
  #   # 但是建议自己去苹果开发者网站证书中手动处理一波provision_profile
  #   # 建议用 bundleId_导出方式 来命名比如: 
  #   #     卖好车的企业包pp文件叫 testEnt_InHouse.mobileprovision
  #   sigh(
  #     # Appfile设置了这边就可以不用了
  #     # app_identifier: "com.devhy.testEnt",
  #     # username: "devhy@xxxx1.com",
  #     # team_id: "TEAMIDXXX1",

  #     # 下载文件的位置
  #     output_path: "build",
  #     # 自动下载签名时，adc里pp名字，貌似只会下载最新的那一个
  #     # provisioning_name: "testEnt_InHouse", 
  #     # 仅下载不创建
  #     readonly: false, 
  #     # 因为是根据BundleID下载，导致adhoc和appstore会优先appstore，导致最后导出报错
  #     adhoc: false, 
  #   )

  #   # 编译配置，编译的scheme，导出包方式，对应的provision_profile名称
  #   gym(
  #     scheme: "YiDian",
  #     # app-store, ad-hoc, package, enterprise, development, developer-id
  #     export_method: "development", 
  #     # 输出日志的目录
  #     buildlog_path: "./fastlane/fastlanelog",
  #     # 输出编译结果
  #     output_directory: "build",
  #     include_bitcode: false,
  #   )
  # end
end
